<?php

class UserController extends Controller
{
	public function actionDelete()
	{
		$this->render('delete');
	}

	public function actionIndex()
	{

		$this->render('index');
	}

	public function actionLogin()
	{
		if(isset($_POST['submit'])){
			$Pusername = app()->request->getPost('username');
			$Ppassword = app()->request->getPost('password');
			importUc();
			list($uid, $username, $password, $email) = uc_user_login($Pusername,$Ppassword);

			
			if($uid<0){
				if($uid==-1){
				sf('warning','用户名不存在或者删除！');
				}elseif($uid == -2){
				sf('warning','密码错误！');
				}
				$this->refresh();
				}else{
				$identity = new UserIdentity($username,$password,$uid);	
			
				$identity->authenticate();
				if($identity->errorCode===UserIdentity::ERROR_NONE){
					$duration=0; // 30 days
					Yii::app()->user->login($identity,$duration);				
					$this->redirect(bu());
					}	

				}
			}
	
		$this->render('login');
	}

	public function actionLogout()
	{
		app()->user->logout();
		$this->redirect(bu());
	}

	public function actionRegister()
	{
		$this->render('register');
	}

	// Uncomment the following methods and override them if needed
	/*
	public function filters()
	{
		// return the filter configuration for this controller, e.g.:
		return array(
			'inlineFilterName',
			array(
				'class'=>'path.to.FilterClass',
				'propertyName'=>'propertyValue',
			),
		);
	}

	public function actions()
	{
		// return external action classes, e.g.:
		return array(
			'action1'=>'path.to.ActionClass',
			'action2'=>array(
				'class'=>'path.to.AnotherActionClass',
				'propertyName'=>'propertyValue',
			),
		);
	}
	*/
}
